package com.itheima.service.impl;

import com.itheima.dao.FileMapper;
import com.itheima.dao.FileSortMapper;
import com.itheima.dao.PictureMapper;
import com.itheima.pojo.File;
import com.itheima.pojo.Picture;
import com.itheima.service.FileService;
import com.itheima.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author xuchangshuo
 * @date 2020/8/6 19:39
 */

@Service
public class FileServiceImpl implements FileService {

    @Autowired
    private FileSortMapper fileSortMapper;

    @Autowired
    private FileMapper fileMapper;

    @Autowired
    private PictureMapper pictureMapper;

    @Autowired
    private IdWorker idWorker;


    @Override
    public File getPicture(String uid) {
        File file = fileMapper.selectByPrimaryKey(uid);
        return file;
    }

    @Override
    public void upload(File file, String projectName, String sortName) {
        fileMapper.insertSelective(file);

        // 添加图片信息
        Picture picture = new Picture();
        picture.setUid(idWorker.nextId() + "");
        picture.setFileUid(file.getUid());
        picture.setPicName(file.getPicName());
        picture.setStatus(1);

        picture.setCreateTime(new Date());
        picture.setUpdateTime(new Date());
        pictureMapper.insertSelective(picture);

    }

}
